//utf-8

//选择合约
function toAddContract(){
	
	var dialogStruct={
			'display':contextRootPath+'/tCMmContract/prepareExecute/toSelectContract',
			'width':1000,
			'height':800,
			'title':'选择合约',
			'isIframe':'false',
			'buttons':[
			           {'text':'确定','action':doAddFromContractSure,'isClose':true},
			  		   {'text':'关闭','isClose':true}
			]
		};
		
		var dialogAdd =jyDialog(dialogStruct).open();

	
}

//增加债权
function toAddDataCredit(){
	
	var obj  = $('#cooperorgCode').length;
	var value;
	if(obj>0){
		value = $('#cooperorgCode').val();
	}else {
		value = $('#dtocooperorgCode').val();
	}
	
	if(value=="" || null ==value){
		alert("请选择载入合约信息！");
		return;
	}
	
	var creditPackageName = $('#dealPackage').val();
	var statementDateStart = $('#statementDateStart').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var publicRepayType = $('#publicRepayType').val();
	if(value!=null && value!=""){
		
		if(null==creditPackageName ||""==creditPackageName){
			alert("请选择或者填写包名！");
			return;
		}
		
		if(null==statementDateStart || ""==statementDateStart){
			alert("请选择账单起始日！");
			return;
		}
		
		if(null==statementDateEnd || ""==statementDateEnd){
			alert("请选择账单结束日！");
			return;
		}
		
		if(statementDateStart>statementDateEnd){
			alert("账单起始日不能大于账单结束日！");
			return;
		}
		
		if(null==publicRepayType || ""==publicRepayType){
			alert("请选择还款方式！");
			return;
		}
	}
	
	var dialogStruct={
			'display':contextRootPath+'/tCMmCreditDetail/prepareExecute/toAddCredit',
			'width':1100,
			'height':600,
			'title':'债权列表',
			'isIframe':'false',
			'buttons':[
			         {'text':'确定','action':doAddCredit,'isClose':true},
			  		 {'text':'关闭','isClose':true}
			]
		};
		
		var dialogAdd =jyDialog(dialogStruct).open();
		
}

//确认债权
function doAddCredit(obj){
	
	var v_ids = iframeCredit.iframeObj["table"].getSelectedIds().join(",");
	var pagIsFull = $('input[name=pagIsFull]:checked').val();
	//如果没有选中 数据则
	if(v_ids == ""&&pagIsFull!="01"){
		alert("请选择债权!");
		return;
	}
	
	var table=iframeCredit.iframeObj["table"];
	var transferIds = table.getSelectedObjs("transferId");
	transferIds = "" + transferIds;
	var thisCreditorValue = table.getSelectedObjs("thisCreditorValue");
	var thisMakeCreditorValue = table.getSelectedObjs("thisMakeCreditorValue");
	thisMakeCreditorValue = "" + thisMakeCreditorValue;
	thisCreditorValue = "" + thisCreditorValue;
	var valueContractCode = $('#dtocontractCode').val();
	var cooperorgCode = $('#dtocooperorgCode').val();
	var ids = table.getSelectedObjs("id");
	var dealType = $('#dealType').val();
	ids = "" + ids;
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var creditPackageName = $('#dealPackage').val();
	var statementDateStart = $('#statementDateStart').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var dtoagreementCode = $('#dtoagreementCode').val();
	var publicRepayType = $('#publicRepayType').val();
	if(pagIsFull!='01'){
		pagIsFull="00";
	}
	
	var dataUrl =contextRootPath + "/cooperorgDeal/updateQuotaDetailByCredit";	
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"transferIds":transferIds,
			"thisMakeCreditorValues":thisMakeCreditorValue,
			//"thisCreditorValue":thisCreditorValue,
			"ids":ids,
			"dealCode":dealCode,
			"contractCode":valueContractCode,
			"cooperorgCode":cooperorgCode,
			"id":id,
			"dealType":dealType,
			"packageNum":creditPackageName,
			"billDate":statementDateStart,
			"billDateEnd":statementDateEnd,
			"repayType":publicRepayType,
			 "argeementCode":dtoagreementCode,
			 "pagIsFull":pagIsFull},
		success: function(results) {
			
			var obj = results.data;
			$("#idValue").val(obj.id);
			$("#dealCode").val(obj.dealCode);
			$("#dealDate").val(obj.dealDate);
			initFnCreditDetailView(transferIds);
			$("#creditDetailTable").show();
			CreditValueSum();
			$("#isDelete").val("true");
			$("#statementDateStart").attr("disabled","disabled");
			$("#statementDateEnd").attr("disabled","disabled");
			$("#publicRepayType").attr("disabled","disabled");
			$("#dealPackage").attr("disabled","disabled");
			alert(results.msg);
			
		}
	});
	
	
	
}

//债权价值合计
function CreditValueSum(){
	var dealCode = $("#dealCode").val();
	var dataUrl =contextRootPath + "/cooperorgDeal/getDealDetailByCreditSumTotal";	
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"dealCode":dealCode},
		error: function(result) {
			
			alert("请查看返回数据是否正确：" + result);
		},
		success: function(results) {
			var obj = results.data;
			$("#detialNumber").val(obj.detialNumber);
			$("#sumCreditorValue").val(obj.sumCreditorValue);
			$("#sumServiceCharge").val(obj.sumServiceCharge);
			$("#sumGuaranteeFee").val(obj.sumGuaranteeFee);
			$("#sumCautionMoney").val(obj.sumCautionMoney);
			var sumFee=obj.sumFee;
			$("#sumFee").val(obj.sumFee);
		}
	});
}



//确认合约
function doAddFromContractSure(){
	var contractCode = iframeSelectContract.iframeObj["table"].getSelectedObjs("contractCode");
	
	 window.location = contextRootPath+'/tCMmContract/prepareExecute/toBackCooperorgDealAdd?contractCode='+contractCode;
	
}

//双击合约
function doAddFromContract(contractCode){
   
	 window.location = contextRootPath+'/tCMmContract/prepareExecute/toBackCooperorgDealAdd?contractCode='+contractCode;
	
}

//返回合约
function returnContract(contractCode){
	
	var dataUrl =contextRootPath + "/tCMmContract/returnContract";	
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"contractCode":contractCode},
		error: function(result) {
			
			alert("请查看返回数据是否正确：" + result);
		},
		success: function(results) {
			var obj = results.data;
			if(obj[0].length<0){
				return;
			}
			var creditorAffirmRule = obj[0].cdto.creditorAffirmRule;
			var dealType = obj[0].cdto.dealType;
			if(creditorAffirmRule=='01'){
				$("#dtocreditorAffirmRule").attr("value","发起方");
			}else if(creditorAffirmRule=='02'){
				$("#dtocreditorAffirmRule").attr("value","接收方");
			}
			$("#creditorAffirmRule").attr("value",dealType);
		}
	});
}

function selectStyle(){
	var cooperorgCode = $('#dtocooperorgCode').val();
	var contractCode = $('#dtocontractCode').val();
	if(cooperorgCode!="" && null !=cooperorgCode){
		$("select[name=cooperorgCode]").find("option[value='" + cooperorgCode + "']").attr("selected",true);
		$("select[name=contractCode]").find("option[value='" + contractCode + "']").attr("selected",true);
	}
}

function isShowCooperorg(){
	$("#creditRestrainTitle").show();
	$("#creditRestrainTitleValue").show();
	$("#creditOperation").show();
	$("#creditDetailOperation").show();
}

function isShowContract(){
	$("#creditPackageColumn").show();
	searchCreditPackage();
}

//查询债权包隐藏标签
var selectOptions=[];
function searchCreditPackage(selectID,updatePackageValue,type){
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var valueContractCode = $('#dtocontractCode').val();
	var dataUrl = contextRootPath + '/cooperorgDeal/getPackageListByAll?cooperorgCode=' + valueCooperorgCode +'&contractCode='+valueContractCode;//+ "&pagType=" + cimsConstant.CREDIT_RESOURCE
	$('#creditPackage').html("<option id='selectValue' name='请选择' value='-1'>请选择</option>");
	$.ajax({
		url: dataUrl,
		type: 'get',
		dataType: 'json',
		data:'',
		success: function(results) {
			var result=results.data;
			var j;
			var resultLength = result.length - 1;
			for (j = 0; j <= resultLength; j++) {
				$('#creditPackage').append("<option name='"+result[j].creditPackageName+"' value='"+result[j].billDate+":"+result[j].billDateEnd+":"+result[j].repayType+"'>"+result[j].creditPackageName+"</option>");
				selectOptions.push(result[j].creditPackageName);
			}
			completePackage(selectOptions,selectID,updatePackageValue,type);
		}
	});
	
}


//保存交易流水
function saveDeal(){
	
	var obj  = $('#cooperorgCode').length;
	var valueCooperorgCode;
	if(obj>0){
		valueCooperorgCode = $('#cooperorgCode').val();
	}else {
		valueCooperorgCode = $('#dtocooperorgCode').val();
	}
	
	var obj  = $('#contractCode').length;
	var valueContractCode;
	if(obj>0){
		valueContractCode = $('#contractCode').val();
	}else {
		valueContractCode = $('#dtocontractCode').val();
	}
	
	var valueQuotaSum = $('#dtoquotaSum').val();
	var creditPackageName = $('#dealPackage').val();
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var sumCreditorValue = $('#sumCreditorValue').val();
	var detialNumber = $('#detialNumber').val();
	var dealType = $('#dealType').val();
	var dtoagreementCode = $('#dtoagreementCode').val();
	var statementDateStart = $('#statementDateStart').val();
	var statementDateEnd = $('#statementDateEnd').val();
	var publicRepayType = $('#publicRepayType').val();
	var dealDate = $('#dealDate').val();
	
	if(null==dealType || ""==dealType){
		alert("请选择交易类型！");
		return;
	}
	if(null==valueCooperorgCode ||""==valueCooperorgCode){
		alert("请选择合作机构！");
		return;
	}
	
	
	if(valueContractCode!=null && valueContractCode!=""){
		if(null==creditPackageName ||""==creditPackageName){
			alert("请选择或者填写包名！");
			return;
		}
		
		if(null==statementDateStart || ""==statementDateStart){
			alert("请选择账单起始日！");
			return;
		}
		
		if(null==statementDateEnd || ""==statementDateEnd){
			alert("请选择账单结束日！");
			return;
		}
		
		if(statementDateStart>statementDateEnd){
			alert("账单起始日不能大于账单结束日！");
			return;
		}
		
		if(null==publicRepayType || ""==publicRepayType){
			alert("请选择还款方式！");
			return;
		}
	}
	
	
	
	if(null==dealCode ||""==dealCode){
		alert("请选择债权！");
		return;
	}
	
		
	if(confirm("确认保存！")){
		var dataUrl =contextRootPath + "/cooperorgDeal/saveCooperorgDeal";
		$.ajax({
			url: dataUrl,
			type: 'post',
			dataType: 'json',
			data:{"cooperorgCode":valueCooperorgCode,
				  "contractCode":valueContractCode,
				  "planSellSum":valueQuotaSum,
				  "creditPackageName":creditPackageName,
				  "dealCode":dealCode,
				  "id":id,
				  "sumCreditorValue":sumCreditorValue,
				  "detialNumber":detialNumber,
				  "dealType":dealType,
				  "agreementCode":dtoagreementCode,
				  "billDate":statementDateStart,
				  "billDateEnd":statementDateEnd,
				  "repayType":publicRepayType,
				  "dealDate":dealDate},
			success: function(results) {
				$("#isDeleteAndIsExport").val("true");
				$("#dealPackage").attr("disabled","disabled");
				$("#publicRepayType").attr("disabled","disabled");
				var winObj = parent.tabs.getTabWinByTitle("转让交易");
				if(winObj)
					winObj.location.reload();
				//parent.tabs.close();
				alert("保存成功！");
			}
		});
	}
	
}


function saveCreditDeal(){
	var dealCode = $('#dealCode').val();
	
	if(null==dealCode ||""==dealCode){
		alert("请选择债权！");
		return;
	}
	
	var dataUrl =contextRootPath + "/tCMmCreditDealDetail/queryListTCMmCreditDealDetail?dealStreamCode=" + dealCode;
	$.ajax({
		url: dataUrl,
		type: 'get',
		dataType: 'json',
		data:'',
		success: function(results) {
			var result=results.data;
			var resultLength = result.length;
			if(resultLength<=0){
				alert("该交易下没有债权！");
			}else {
				saveDeal();
			}
		}
	});
}

//试算
function settleCreditDeal(){
	var dealCode = $('#dealCode').val();
	
	if(null==dealCode || ""==dealCode){
		alert("请先导入债权确认信息！");
		return;
	}
	
	if(confirm("请确认导入的债权信息!")){
		var dataUrl =contextRootPath + "/settle/testSettleCooperorgDeal";
		$.ajax({
			url: dataUrl,
			type: 'post',
			dataType: 'json',
			data:{"dealCode":dealCode},
			success: function(results) {
				
			}
		});
	}
}

//选择债权包
function creditPackageOperation(obj){
	var text = obj.value;
	var selectObj = $("#creditPackage option[name="+obj.value+"]").length;
	var textValue = "" + $("#creditPackage option[name="+obj.value+"]").val();
	
	
	if (selectObj!=0){
			var textValueArray = textValue.split(":");
				$("#statementDateStart").val(textValueArray[0]);
				$("#statementDateEnd").val(textValueArray[1]);
				$("#publicRepayType option[value="+textValueArray[2]+"]").attr("selected","true");
				$('#publicRepayType').attr("disabled","disabled");
				$('#statementDateStart').attr("disabled","disabled");
				$('#statementDateEnd').attr("disabled","disabled");
			if(textValueArray[0]=="0"){
				$('#statementDateStart').removeAttr("disabled");
				$("#statementDateStart").val("");
			}
			if(textValueArray[1]=="0"){
				$('#statementDateEnd').removeAttr("disabled");
				$("#statementDateEnd").val("");
			}
			if(textValueArray[2]=="null"){
				$('#publicRepayType').removeAttr("disabled");
			}
			
	}else {
		$('#publicRepayType').removeAttr("disabled");
		$('#statementDateStart').removeAttr("disabled");
		$('#statementDateEnd').removeAttr("disabled");
		$("#statementDateStart").val("");
		$("#statementDateEnd").val("");
	}
	
}

//债权包输入
function creditPackageOperationWrite(obj){
	
	var valueWrite = obj.value;
	$("#creditPackage option[name='"+valueWrite+"']").attr("selected","true");
	var value = $("#creditPackage option[name='"+valueWrite+"']").val();
	
	
	if(-1==value){
		var textValue = $("#creditPackage").find("option:selected").val();
		$("#creditPackage option[value="+textValue+"]").attr("selected","true");
		$('#statementDate').removeAttr("disabled");
		$("#creditPackageWrite").val("");
		
	}else if (value=="1"){
		var textValue = $("#creditPackage").find("option:selected").val();
		$("#statementDate option[value="+textValue+"]").attr("selected","true");
		$('#statementDate').attr("disabled","disabled");

	}else if(value=="16"){
		var textValue = $("#creditPackage").find("option:selected").val();
		$("#statementDate option[value="+textValue+"]").attr("selected","true");
		$('#statementDate').attr("disabled","disabled");
	}else{
		$('#statementDate').removeAttr("disabled");
	}
	
}

//删除债权
function deleteCredit(){
	
	var isDelete = $("#isDelete").val();
	if(false==isDelete || "false"==isDelete){
		alert("没有债权可删除，请新增！");
		return;
	}
	
	var table=iframeCreditView.iframeObj["table"];
	var transferIds = table.getSelectedObjs("transferId");
	transferIds = transferIds + "";
	var v_ids = iframeCreditView.iframeObj["table"].getSelectedIds().join(",");
	
	var dealCode = $('#dealCode').val();
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待删除的数据！");
		return;
	}
	if(confirm("您确认要删除选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/cooperorgDeal/deleteDetailByCredit",
            data:{"transferIds":transferIds
          	  ,"dealCode":dealCode},
          	error:function(){
          		CreditValueSum();
          	},
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframeCreditView.iframeObj["table"].removeSelectedRow();
            		CreditValueSum();
            	}
            	
            	
            }
        });
    }
}


/*function packageDay(url){
	
	 $.ajax({
         type:"get",
         dataType : "json",
         url:url,
         success:function(msg){
         	
        	 
         	
         	
         }
     });
}*/

//页面关闭按钮操作
function closeFather(){
	var winObj = parent.tabs.getTabWinByTitle("转让交易");
	if(null==winObj){
		parent.tabs.close();
	}else{
		winObj.location.reload();
		parent.tabs.close();
	}
	
}

//债权价值合计
function sumSelectValue(){
	var thisMakeCreditorValues = iframeCredit.iframeObj["table"].getSelectedObjs("thisMakeCreditorValue");
	var thisMakeCreditorValueLength = thisMakeCreditorValues.length;
	var i;
	var selectedCreditValue = $("#sumCreditorValue").val();
	if(selectedCreditValue==null||selectedCreditValue==""){
		selectedCreditValue = "0";
	}
	selectedCreditValue  = parseFloat(selectedCreditValue);
	var thisMakeCreditorValue;
	if(thisMakeCreditorValueLength>0){
		for(i=0;i<thisMakeCreditorValueLength;i++){
			thisMakeCreditorValue =parseFloat(thisMakeCreditorValues[i]);
			selectedCreditValue  += thisMakeCreditorValue;
		}
		selectedCreditValue = selectedCreditValue.toFixed(2);
		$("#selectedCreditValue").val(selectedCreditValue);
	}else{
		var sumCreditorValue = $("#sumCreditorValue").val();
		if(sumCreditorValue==null||sumCreditorValue==""){
				$("#selectedCreditValue").val(0);
		}else{
				$("#selectedCreditValue").val(sumCreditorValue);
		}
	}
	
}

//费用计算功能
function costParameterSum(param){
	var costCode = $("#"+param).val();
	var url = contextRootPath + "/tCMmCostParam/costSumByParam";
	var dealCode = $('#dealCode').val();
	var creditPackageName = $('#dealPackage').val();
	var obj  = $('#contractCode').length;
	var contractCode;
	if(obj>0){
		contractCode = $('#contractCode').val();
	}else {
		contractCode = $('#dtocontractCode').val();
	}
	var obj  = $('#cooperorgCode').length;
	var cooperorgCode;

	if(obj>0){
		cooperorgCode = $('#cooperorgCode').val();
	}else {
		cooperorgCode = $('#dtocooperorgCode').val();
	}
	if(costCode=="-1"){
		alert("请选择费用参数！");
		return;
	}
	
	var param = {"cooperorgCode":cooperorgCode,"dealCode":dealCode,"costCode":costCode,"contractCode":contractCode,"creditPackageName":creditPackageName};
	
	jyAjax(url,param,function(msg){
		alert(msg.msg);
    	var v_status = msg.status;
    	if(v_status.indexOf('ok') >-1){
    		var result=msg.data;
    		iframeCreditView.iframeObj["table"].query();
    		CreditValueSum();
    	}
	});
	
}

//债权 结算功能（推送核心） zhoupeng 2016-4-18
function costParameterConfirm(){
	var dealCode = $('#dealCode').val();
	//如果没有选中 数据则
//	if(v_ids == ""){
//		alert("请选择待发送的数据！");
//		return;
//	}
	var url = contextRootPath + "/tCMmCostParam/costParameterConfirm";

	var param = {"dealCode":dealCode};
	
	jyAjax(url,param,function(msg){
		alert(msg.msg);
    	var v_status = msg.status;
    	if(v_status.indexOf('ok') >-1){
    		var result=msg.data;
    		//iframeCreditView.iframeObj["table"].query();
    	}
	});
	
}

//月还 结算申请功能（推送核心） zhoupeng 2016-4-26
function settleBillConfirm(obj){
	   var startDate = $("input[name=startDate]").val();
	    var endDate = $("input[name=endDate]").val();
		var cooperorgCode = $("#cooperorgCode").val();
		var packageNum = $("input[name=packageNum]").val();
		var dealCode = $("input[name=dealCode]").val();
		var settleApplyId = $("input[name=settleApplyId]").val();
		var transferId = $("input[name=transferId]").val();
		var creditCode = $("input[name=creditCode]").val();
		
		var settlementSign = $("select[name=settlementSign]").val();
		var creditSource = $("select[name=creditSource]").val();
		var abnormalSettle = $("select[name=abnormalSettle]").val();
		
		var contractCode = $("#contractCode").val();
		var replaceType = $("select[name=replaceType]").val();
	    
		var url = contextRootPath+"/creditsettlebill/settleBillConfirm?beginSettleDate=" + startDate + "&endSettleDate="+endDate
	       +"&cooperorgCode="+cooperorgCode+"&contractCode=" + contractCode + "&packageNum=" + packageNum
	       +"&replaceType=" + replaceType+"&costState="+settlementSign+"&dealCode="+dealCode+"&creditSource="+creditSource
	       +"&planStatus="+ abnormalSettle+"&transferId="+transferId+"&creditCode="+creditCode +"&settleApplyId="+settleApplyId;
		
		if(obj=='all'){
			 url = contextRootPath+"/creditsettlebill/settleBillConfirm";
		}else{
			if(startDate==null||startDate==""|| endDate==null||endDate==""){
		    	alert("结算日期不能为空！");
		    	return ;
		    }
			if(null==cooperorgCode ||""==cooperorgCode){
				alert("请选择合作机构！");
				return;
			}
		}

	art.dialog({title: '询问', content: '您确认结算状态为“待结算”的“退费金额”是否正确？', ok: function () {
		  jyAjax(url,null,function(result){
				//alert(result.msg);
			    var icon = "warning";
			    if(result.status=="ok"){icon = "succeed"; }else if(result.status=="error"){icon = "error"; }
			    var content = '<p>'+result.msg+'</p>';
				art.dialog({title: '处理结果', content:content , ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10, icon: icon,width: 450});
				queryData();
			});
		}, cancel: true, icon: 'question', lock:true, background:'#600', opacity: 0.10});
		
	
	/*if(confirm("您确认结算状态为“待结算”的“退费金额”是否正确？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/creditsettlebill/settleBillConfirm",
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            }
        });
    }*/
}



//删除 二次购买月还 事件
function deleteSettleAndSecondBuy(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	var v_dealCodes = iframe.iframeObj["table"].getSelectedObjs("dealCode").join(",");
	//如果没有选中 数据则
	if(v_dealCodes == ""){
		alert("请选择待删除的数据！");
		return;
	}
	if(confirm("您确认要删除选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/settle/doDeleteSettle?dealCodes="+v_dealCodes,
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframe.iframeObj["table"].removeSelectedRow();
            	}
            	
            	
            }
        });
    }
}

function updateSettle(){
	$.ajax({
		url: contextRootPath+"/creditDealController/realTimeUpdateSettleResult",
		type: 'post',
		dataType: 'json',
		success: function(msg) {
				//art.dialog({title: '处理结果', content: msg.msg, ok: function () {return true; }, lock:true, background:'#600', opacity: 0.10});
				alert(msg.msg);
				var v_status = msg.status;
		    	if(v_status.indexOf('ok') >-1){
		    		queryData();
		    	}
				
		}
	});
}

function finishDeal(){
	
	var obj  = $('#cooperorgCode').length;
	var valueCooperorgCode;
	if(obj>0){
		valueCooperorgCode = $('#cooperorgCode').val();
	}else {
		valueCooperorgCode = $('#dtocooperorgCode').val();
	}
	if(null==valueCooperorgCode ||""==valueCooperorgCode){
		alert("请选择合作机构！");
		return;
	}
	
	var dealCode = $('#dealCode').val();
	if(dealCode==""){
		alert("请先点击保存！");
	}
	var dataUrl =contextRootPath + "/cooperorgDeal/finishDeal";
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"cooperorgCode":valueCooperorgCode,"dealCode":dealCode},
		success: function(results) {
			if(results.status=="failed"){
				alert("发送完成失败！"+results.msg);
			}else{
				alert("发送完成成功！");
			}
		}
	});
	
}
/**确认转让交易，发送核心*/
function confirmDeal(){
	
	var obj  = $('#cooperorgCode').length;
	var valueCooperorgCode;
	if(obj>0){
		valueCooperorgCode = $('#cooperorgCode').val();
	}else {
		valueCooperorgCode = $('#dtocooperorgCode').val();
	}
	if(null==valueCooperorgCode ||""==valueCooperorgCode){
		alert("请选择合作机构！");
		return;
	}
	
	var dealCode = $('#dealCode').val();
	var creditAffiliation = $("#creditAffiliation").val();
	if(dealCode==""){
		alert("请先点击保存！");
	}
	var dataUrl =contextRootPath + "/cooperorgDeal/confirmDeal";
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"cooperorgCode":valueCooperorgCode,
			  "dealCode":dealCode,
			  "creditAffiliation":creditAffiliation},
		success: function(results) {
			if(results.status=="failed"){
				alert("发送完成失败！"+results.msg);
			}else{
				alert("发送完成成功！");
			}
		}
	});
	
}

$(document).ready(function(){
	$('#creditorAffirmRule').attr("disabled","disabled");
});
